import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Layout from '@/layout/Index.vue'
import { routerGuards } from './routerGuards'

const routes: Array<RouteRecordRaw> = [
    {
        path: '/login',
        name: 'login',
        component: () => import('@/layout/login/Login.vue'),
        meta: {
            title: '登录'
        }
    },
    {
        path: '/404',
        name: '404',
        component: () => import('@/layout/error/404.vue'),
        meta: {
            title: '404'
        }
    },
    {
        path: '/',
        name: 'index',
        redirect: '/home',
        component: Layout,
        meta: {
            title: '主页'
        },
        children: [
            {
                path: '/home',
                name: 'home',
                component: () => import('@/views/home/Home.vue'),
                meta: {
                    title: '后台首页',
                    icon: 'HomeFilled'
                }
            }
        ]
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

// 挂载路由
export async function setupRouter(app: any) {
    routerGuards(router)
    app.use(router)
    await router.isReady()
}

export default router
